------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_25
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/08_prepare_independence.log
  log type:  text
 opened on:  19 Sep 2022, 11:38:55

. *********************************************************************
. ********Preparation of ITANES 1996 for independence******************
. *********************************************************************
. 
. * directory definitions 
. 
.         project, doinfo
project PlaceBased_analysis > Project Name: PlaceBased_analysis
project PlaceBased_analysis > Project Dir.: /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication
project PlaceBased_analysis > Build start : 19sep2022, 11:38:37
project PlaceBased_analysis > Do-file Name: 08_prepare_independence.do
project PlaceBased_analysis > Enclosing do-files:
project PlaceBased_analysis >     PlaceBased_analysis.do

.         global pdir "`r(pdir)'"                                                 // the project's main dir.

.         global dofile "`r(dofile)'"                                             // do-file's stub name

.         global data_original = "$pdir/data_original"  //data directory for coded data 

.         global data_coded = "$pdir/data_coded"  //data directory for coded data 

.         global figures = "$pdir/results/figures"  //data directory for figures

.         global tables = "$pdir/results/tables"  //data directory for tables

. 
. *
.         // 1996 election study for placebo with IV: 
.         project, original("$data_original/election studies/1996/ENG_1996.dta")
project PlaceBased_analysis > do-file uses original: "data_original/election studies/1996/ENG_1996.dta" filesig(3362166840:2373859)

. 
.         use "$data_original/election studies/1996/ENG_1996.dta", clear
(Written by R)

.         rename q236 comune_id 

.         rename q235 province_id

.         
.         tempfile itanes1996

.         save `itanes1996'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000004 saved as .dta format

. 
. *
.         // read in ugs data:
.         project, uses("$data_coded/placebased_mapdata.dta")
project PlaceBased_analysis > do-file uses: "data_coded/placebased_mapdata.dta" filesig(331457870:323923)

.         
.         use "$data_coded/placebased_mapdata.dta", clear 

.         keep comune_id ugs_yn km_to_ugs

.         
.         tempfile ugs

.         save `ugs'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000005 saved as .dta format

. 
. *
.         // we also need pre-treatment population. Here we can simply use the same Campante data as the ugs stations:
.         project, original("$data_original/Campanteetal/mergefile.xls")
project PlaceBased_analysis > do-file uses original: "data_original/Campanteetal/mergefile.xls" filesig(3380594693:2736640)

.         
.         import excel "$data_original/Campanteetal/mergefile.xls", sheet("COMUNI 11_03_2013") firstrow clear 
(25 vars, 8,161 obs)

. 
.         ** rename: 
.         rename E comune_id

.         rename Popolazionelegale200121102 population_2001

. 
.         ** minimalize data: 
.         keep comune_id population_2001

. 
.         tempfile pop2001

.         save `pop2001'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000006 saved as .dta format

. 
. *
.         // Important our webscraped M5S data and make some cleanings:
.         project, original("$data_coded/events_comune_neigh_nga.csv")
project PlaceBased_analysis > do-file uses original: "data_coded/events_comune_neigh_nga.csv" filesig(2414589165:3213673)

. 
.         import delimited "$data_coded/events_comune_neigh_nga.csv", clear 
(177 vars, 7,998 obs)

. 
.         ** date cleanings:
.         replace hist_days=round(hist_days, 0.1)
(699 real changes made)

.         replace hist_days=0 if hist_days==.
(7,213 real changes made)

.         
.         keep wn_* comune_id hist_days

.         
.         ** replace missings (if any)
.         foreach w of varlist wn_* {
  2.                 replace `w'=0 if `w'==.
  3.         }
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(7,213 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)

.         
.         ** minimalize data: 
.         keep comune_id wn_treat_campaign hist_days

. 
.         tempfile meetup

.         save `meetup'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000007 saved as .dta format

. 
. *
.         // open survey data and merge:
.         use `itanes1996'
(Written by R)

. 
.         merge m:m comune_id using `ugs'

    Result                      Number of obs
    -----------------------------------------
    Not matched                         7,593
        from master                       158  (_merge==1)
        from using                      7,435  (_merge==2)

    Matched                             2,344  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(7,435 observations deleted)

.         drop _merge

.         
.         merge m:m comune_id using `pop2001'

    Result                      Number of obs
    -----------------------------------------
    Not matched                         7,754
        from master                       157  (_merge==1)
        from using                      7,597  (_merge==2)

    Matched                             2,345  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(7,597 observations deleted)

.         drop _merge

.         
.         merge m:m comune_id using `meetup'

    Result                      Number of obs
    -----------------------------------------
    Not matched                         7,593
        from master                       158  (_merge==1)
        from using                      7,435  (_merge==2)

    Matched                             2,344  (_merge==3)
    -----------------------------------------

.         drop if _merge==2
(7,435 observations deleted)

.         drop _merge

. 
.         ** we standardize the exposure variable as discussed in the paper 
.         gen exposure_pop=population_2001/1000
(157 missing values generated)

. 
.         foreach var of varlist wn_* {
  2.                 gen std_`var'=log((`var'/log(exposure_pop))+1)
  3.         }
(158 missing values generated)

.         
.         ** create constant to trick reghdfe
.         gen constant=1

. 
.         *clean the data & make it meaningful based on codebook:
. 
.         gen urbanity=q238

.         
.         gen pol_int=q5
(4 missing values generated)

.         revrs pol_int, replace

.         
.         gen radio=q33
(1 missing value generated)

.         
.         foreach var of varlist q39-q41 {
  2.                 gen efficacy_`var'=`var'
  3.                 revrs efficacy_`var', replace
  4.         }
(55 missing values generated)
(52 missing values generated)
(66 missing values generated)

.         rename efficacy_q39 efficacy_self 

.         rename efficacy_q40 efficacy_rep 

.         rename efficacy_q41 efficacy_cand

.         
.         gen democrat=0

.         replace democrat=1 if q42==1
(2,034 real changes made)

.         
.         gen dem_sat=q43
(33 missing values generated)

.         revrs dem_sat 

.         
.         gen lr=q44
(222 missing values generated)

.         
.         gen scal_berlu=q107
(26 missing values generated)

.         gen scal_bossi=q109
(52 missing values generated)

.         gen scal_fini=q110
(31 missing values generated)

.         gen scal_scalfaro=q110
(31 missing values generated)

.         
.         gen party_id=q131
(574 missing values generated)

.         tab party_id, gen(party_id)

   party_id |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        105        5.45        5.45
          2 |         47        2.44        7.88
          3 |         24        1.24        9.13
          4 |         36        1.87       11.00
          5 |         18        0.93       11.93
          6 |        517       26.82       38.74
          7 |        165        8.56       47.30
          8 |        258       13.38       60.68
          9 |         30        1.56       62.24
         10 |         27        1.40       63.64
         11 |        299       15.51       79.15
         12 |        140        7.26       86.41
         13 |         11        0.57       86.98
         14 |         27        1.40       88.38
         15 |          1        0.05       88.43
         17 |         17        0.88       89.32
         18 |         37        1.92       91.23
         19 |         51        2.65       93.88
         20 |         99        5.13       99.01
         21 |          8        0.41       99.43
         22 |         11        0.57      100.00
------------+-----------------------------------
      Total |      1,928      100.00

.         
.         gen vote94=q133
(173 missing values generated)

.         tab vote94, gen(vote94_)

     vote94 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        146        6.27        6.27
          2 |         88        3.78       10.05
          3 |        580       24.90       34.95
          4 |        141        6.05       41.00
          5 |         45        1.93       42.94
          6 |        571       24.52       67.45
          7 |        283       12.15       79.60
          8 |        158        6.78       86.39
          9 |         32        1.37       87.76
         10 |         67        2.88       90.64
         11 |         10        0.43       91.07
         12 |         20        0.86       91.93
         13 |         24        1.03       92.96
         14 |         44        1.89       94.85
         15 |         42        1.80       96.65
         16 |         78        3.35      100.00
------------+-----------------------------------
      Total |      2,329      100.00

.         
.         gen turnout96=0

.         replace turnout96=1 if q143==1
(2,432 real changes made)

.         
.         gen vote96pro=q154
(440 missing values generated)

.         tab vote96pro, gen(vote96pro_)

  vote96pro |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        150        7.27        7.27
          2 |         79        3.83       11.11
          3 |        573       27.79       38.89
          4 |        179        8.68       47.58
          5 |        358       17.36       64.94
          6 |         62        3.01       67.94
          7 |        321       15.57       83.51
          8 |        158        7.66       91.17
          9 |         34        1.65       92.82
         10 |         53        2.57       95.39
         11 |         14        0.68       96.07
         12 |         25        1.21       97.28
         13 |         56        2.72      100.00
------------+-----------------------------------
      Total |      2,062      100.00

.         
.         gen vote96maj=q151
(534 missing values generated)

.         tab vote96maj, gen(vote96maj_)

  vote96maj |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |      1,057       53.71       53.71
          2 |        750       38.11       91.82
          3 |        117        5.95       97.76
          4 |          8        0.41       98.17
          5 |         13        0.66       98.83
          6 |         23        1.17      100.00
------------+-----------------------------------
      Total |      1,968      100.00

.         
.         gen age=q198+17

.         
.         gen unemployed=0

.         replace unemployed=1 if q202==5
(166 real changes made)

.         
.         gen female=0

.         replace female=1 if q234==2
(1,198 real changes made)

.         
.         gen econ_worse=0 if  q3!=.
(44 missing values generated)

.         replace econ_worse=1 if  q3==2
(1,195 real changes made)

.         
.         gen econ_worse_personal=0 if  q4!=.
(6 missing values generated)

.         replace econ_worse_personal=1 if  q4==2
(831 real changes made)

.         
.         gen education=q199
(2 missing values generated)

.         
.         gen religiosity=q136
(16 missing values generated)

.         revrs religiosity, replace

.         
.         gen log_hist=log(hist_days+1)
(158 missing values generated)

.         gen log_ugs=log(km_to_ugs+1)
(158 missing values generated)

.         
.         **renaming exposure variables to ease up reading of analyses code:
.         *rename std_n_treat_referendum m5s_referendum
.         *rename n_total m5s_total
.         
.         **labeling variables 
.         lab var hist_days "days since formation"

.         lab var log_hist "log days since formation"

.         lab var log_ugs "log distance to closest UGS (in km)"

.         lab var religiosity "church attendance (1-5)"   

.         lab var age "age (18-85)"       

.         lab var unemployed "unemployed (0,1)"   

.         lab var education "education (1-7)"     

.         lab var female "female (0,1)"   

.         lab var pol_int "political interest (1-4)"

.         lab var radio "radio (1-5)"

.         lab var efficacy_self "self efficacy (1-4)"

.         lab var efficacy_rep "candidates lose touch (1-4)"

.         lab var efficacy_cand "candidates not parties relevant (1-4)"

.         lab var democrat "supports democracy (0,1)"

.         lab var dem_sat "satisfied with demo in Italy (1-4)"

.         lab var lr "left-right self (1-5)"

.         lab var scal_berlu "scalometer Berlusconi (1-10)"

.         lab var scal_bossi "scalometer Bossi (1-10)"

.         lab var scal_scalfaro "scalometer Scalfaro (1-10)"

.         lab var party_id6 "PiD PD (0,1)"

.         lab var party_id11 "PiD AN (0,1)"

.         lab var party_id8 "PiD FI (0,1)"

.         lab var party_id7 "PiD RC (0,1)"

.         lab var party_id12 "PiD LN (0,1)"

.         lab var party_id1 "PiD Populari (0,1)"

.         lab var vote94_3 "PD 1994 (0,1)"

.         lab var vote94_6 "FI 1994 (0,1)"

.         lab var vote94_7 "AN 1994 (0,1)"

.         lab var vote94_8 "LN 1994 (0,1)"

.         lab var vote94_1 "PPI 1994 (0,1)"

.         lab var vote94_4 "RC 1994 (0,1)"

.         lab var turnout96 "turnout 1996 (0,1)"

.         lab var vote96pro_3 "PD 1996 (0,1)"

.         lab var vote96pro_5 "FI 1996 (0,1)"

.         lab var vote96pro_7 "AN 1996 (0,1)"

.         lab var vote96pro_8 "LN 1996 (0,1)"

.         lab var vote96pro_1 "PPI 1996 (0,1)"

.         lab var vote96pro_4 "RC 1996 (0,1)"

.         lab var vote96maj_1 "Ulivo (0,1)"

.         lab var vote96maj_2 "POL (0,1)"

.         lab var vote96maj_3 "LN (0,1)"

.         lab var std_wn_treat_campaign "M5S: referendum"

.         lab var population_2001 "population in 2001"

.         
.         save "$data_coded/placebased_independence.dta", replace
(file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_independence.dta not found)
file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_independence.dta saved

. 
. * 
.         // report any data we create with this do file: 
.         project, creates("$data_coded/placebased_independence.dta")     
project PlaceBased_analysis > do-file creates: "data_coded/placebased_independence.dta" filesig(3455068160:3069934)

. 
. 
end of do-file
      name:  plog_25
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/08_prepare_independence.log
  log type:  text
 closed on:  19 Sep 2022, 11:39:00
------------------------------------------------------------------------------------------------------------------------------------
